//
//  SEGTimeView.m
//  YYKitDemo
//
//  Created by 刘山 on 2017/11/2.
//  Copyright © 2017年 Sam. All rights reserved.
//

#import "SEGTimeView.h"
#import "WBTextLinePositionModifier.h"

// 内容模型
//@implementation SEGTimeModel
//@end

// 容器布局
@implementation SEGTimeLayout
- (void)setLayoutWithData:(NSString *)data {
    _timeSize = CGSizeZero;
    _textLayout = nil;
    
    if (!data) return;
    if (data.length == 0) return;
    
    
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:[SEGUtils getShowDateWithTimer:[NSString stringWithFormat:@"%@", data]]];
    text.yy_color = kColor_3;
    text.yy_font = [UIFont systemFontOfSize:13];
    
    SEGTextContainer *container = [SEGTextContainer containerWithSize:CGSizeMake(HUGE,HUGE)];
    _textLayout = [SEGTextLayout layoutWithContainer:container text:text];
    
    _timeSize = [text boundingRectWithSize:CGSizeMake(HUGE, HUGE) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
}
@end

//  控件
@implementation SEGTimeView
- (instancetype)initWithFrame:(CGRect)frame {
    if (frame.size.width == 0 && frame.size.height == 0) {
        frame.size.width = LYScreenWidth() / 4;
    }
    self = [super initWithFrame:frame];
    _timeLabel = [SEGLabel new];
    _timeLabel.displaysAsynchronously = YES;
    _timeLabel.ignoreCommonProperties = YES;
    _timeLabel.fadeOnHighlight = NO;
    _timeLabel.fadeOnAsynchronouslyDisplay = NO;
    [self addSubview:_timeLabel];
    return self;
}

-(void)setLayout:(SEGTimeLayout*)layout{
    self.height = layout.timeSize.height;
    self.width = layout.timeSize.width <= LYScreenWidth() / 4 ? layout.timeSize.width: LYScreenWidth() / 4;
    
    _timeLabel.frame = self.bounds;
    _timeLabel.textLayout = layout.textLayout;
}
@end



